package com.shenmazong.grade.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.grade.entity.TbExamGrade;
import com.shenmazong.grade.entity.TbExamSkillGradeDetail;
import com.shenmazong.grade.entity.TbExamTheoryGradeDetail;
import com.shenmazong.grade.mapper.TbExamSkillGradeDetailMapper;
import com.shenmazong.grade.mapper.TbExamTheoryGradeDetailMapper;
import com.shenmazong.grade.service.ExamGradeService;
import com.shenmazong.grade.mapper.TbExamGradeMapper;
import com.shenmazong.util.ChooseIsNull;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *serviceImpl Qi
 */
@Service
public class ExamGradeServiceImpl extends ServiceImpl<TbExamGradeMapper, TbExamGrade>
    implements ExamGradeService {

    @Autowired
    private  TbExamGradeMapper  gradeMapper;
    @Autowired
    private TbExamSkillGradeDetailMapper skillGDMapper;
    @Autowired
    private TbExamTheoryGradeDetailMapper theoryGDMapper;


    @Override
    public ResultResponse saveExamGrade(TbExamGrade tbExamGrade) {
        int i = gradeMapper.insert(tbExamGrade);
        if(i<1){
            return ResultResponse.FAILED("新增失败");
        }
        return ResultResponse.SUCCESS(gradeMapper.selectById(tbExamGrade.getGradeId()));
    }

    @Override
    public ResultResponse deleteExamGrade(BatchChooseIdVo chooseIdVo) {
        if (ChooseIsNull.idsIsNull(chooseIdVo)){
            return ResultResponse.FAILED("未选择要删除的数据");
        }
        int i = gradeMapper.deleteBatchIds(chooseIdVo.getIds());
        if(i<1){
            return ResultResponse.FAILED("删除失败");
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateExamGrade(TbExamGrade tbExamGrade) {
        int i = gradeMapper.updateById(tbExamGrade);
        if(i<1){
            return ResultResponse.FAILED("修改失败");
        }
        return ResultResponse.SUCCESS(gradeMapper.selectById(tbExamGrade.getGradeId()));
    }

    @Override
    public ResultResponse listExamGrade(ListParamVo paramVo) {
        //非空判断
        if(paramVo.getParamMap().size()==0 || paramVo.getParamMap().get("schoolId")==null){
            return ResultResponse.FAILED("无效查询条件");
        }

        IPage<TbExamGrade> page = new Page<>(paramVo.getCurrent(), paramVo.getSize());
        IPage<TbExamGrade> selectPage = gradeMapper.selectPage(page,null);
        return ResultResponse.SUCCESS(selectPage);
    }

    @Override
    public ResultResponse saveExamSkillGradeDetail(TbExamSkillGradeDetail tbExamSkillGradeDetail) {
        int i = skillGDMapper.insert(tbExamSkillGradeDetail);
        if(i<1){
            return ResultResponse.FAILED("新增失败");
        }
        return ResultResponse.SUCCESS(skillGDMapper.selectById(tbExamSkillGradeDetail.getSkillDetailId()));
    }

    @Override
    public ResultResponse deleteExamSkillGradeDetail(BatchChooseIdVo chooseIdVo) {
        if (ChooseIsNull.idsIsNull(chooseIdVo)){
            return ResultResponse.FAILED("未选择要删除的数据");
        }
        int i = skillGDMapper.deleteBatchIds(chooseIdVo.getIds());
        if(i<1){
            return ResultResponse.FAILED("删除失败");
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateExamSkillGradeDetail(TbExamSkillGradeDetail tbExamSkillGradeDetail) {
        int i = skillGDMapper.updateById(tbExamSkillGradeDetail);
        if(i<1){
            return ResultResponse.FAILED("修改失败");
        }
        return ResultResponse.SUCCESS(skillGDMapper.selectById(tbExamSkillGradeDetail.getSkillDetailId()));
    }

    @Override
    public ResultResponse listExamSkillGradeDetail(ListParamVo paramVo) {
        //非空判断
        if(paramVo.getParamMap().size()==0 || paramVo.getParamMap().get("studentId")==null){
            return ResultResponse.FAILED("无效查询条件");
        }

        IPage<TbExamSkillGradeDetail> page = new Page<>(paramVo.getCurrent(), paramVo.getSize());
        IPage<TbExamSkillGradeDetail> selectPage = skillGDMapper.selectPage(page,null);
        return ResultResponse.SUCCESS(selectPage);
    }

    @Override
    public ResultResponse saveExamTheoryGradeDetail(TbExamTheoryGradeDetail tbExamTheoryGradeDetail) {
        int i = theoryGDMapper.insert(tbExamTheoryGradeDetail);
        if(i<1){
            return ResultResponse.FAILED("新增失败");
        }
        return ResultResponse.SUCCESS(theoryGDMapper.selectById(tbExamTheoryGradeDetail.getTheoryDetailId()));
    }

    @Override
    public ResultResponse deleteExamTheoryGradeDetail(BatchChooseIdVo chooseIdVo) {
        if (ChooseIsNull.idsIsNull(chooseIdVo)){
            return ResultResponse.FAILED("未选择要删除的数据");
        }
        int i = theoryGDMapper.deleteBatchIds(chooseIdVo.getIds());
        if(i<1){
            return ResultResponse.FAILED("删除失败");
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateExamTheoryGradeDetail(TbExamTheoryGradeDetail tbExamTheoryGradeDetail) {
        int i = theoryGDMapper.updateById(tbExamTheoryGradeDetail);
        if(i<1){
            return ResultResponse.FAILED("修改失败");
        }
        return ResultResponse.SUCCESS(theoryGDMapper.selectById(tbExamTheoryGradeDetail.getTheoryDetailId()));
    }

    @Override
    public ResultResponse listExamTheoryGradeDetail(ListParamVo paramVo) {
        //非空判断
        if(paramVo.getParamMap().size()==0 || paramVo.getParamMap().get("studentId")==null){
            return ResultResponse.FAILED("无效查询条件");
        }

        IPage<TbExamTheoryGradeDetail> page = new Page<>(paramVo.getCurrent(), paramVo.getSize());
        IPage<TbExamTheoryGradeDetail> selectPage = theoryGDMapper.selectPage(page,null);
        return ResultResponse.SUCCESS(selectPage);
    }
}




